package pqt;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.*;
import javax.swing.event.ChangeEvent;


public class ClosableTabbedPane extends JTabbedPane{
	
	private TabCloseUI closeUI = new TabCloseUI(this);
	
	public void paint(Graphics g){
		super.paint(g);
		closeUI.paint(g);
	}
	
	public void addTab(String title, Component component) {
		super.addTab(title+"  ", component);
		setSelectedComponent(component);
	}
	
	
	public String getTabTitleAt(int index) {
		return super.getTitleAt(index).trim();
	}
	
	public boolean existTab(String tabName) {
		
		
		for(int i=0;i<super.getTabCount();i++) {
			if(tabName.equalsIgnoreCase(getTabTitleAt(i))) {
				setSelectedComponent(super.getComponent(i));
				return true;
			}
		}
		
		return false;
	}
	
	public void removeTab(String name) {
		
		for(int i=0;i<super.getTabCount();i++) {
			if(name.equalsIgnoreCase(getTabTitleAt(i))) {
				super.remove(i);
			}
		}
	}

	
       
    

	
}
